package com.lecyon.farm.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.lecyon.farm.base.BaseRequestPageVo;
import com.lecyon.farm.base.BaseRequestVo;
import com.lecyon.farm.base.BaseResponse;
import com.lecyon.farm.base.RestResponse;
import com.lecyon.farm.common.CommonService;
import com.lecyon.farm.common.constant.CommonConstant;
import com.lecyon.farm.common.constant.FarmSysConstant;
import com.lecyon.farm.common.enums.ExcelFileEnum;
import com.lecyon.farm.common.exception.FarmException;
import com.lecyon.farm.entity.FmCar;
import com.lecyon.farm.entity.FmWorkDetails;
import com.lecyon.farm.entity.JsSysOffice;
import com.lecyon.farm.mapper.FmWorkDetailsMapper;
import com.lecyon.farm.service.IExcelService;
import com.lecyon.farm.service.IFmCarService;
import com.lecyon.farm.service.IFmWorkDetailsService;
import com.lecyon.farm.service.IJsSysOfficeService;
import com.lecyon.farm.util.RedisUtils;
import com.lecyon.farm.util.ResultUtil;
import com.lecyon.farm.util.StringHelper;
import com.lecyon.farm.util.ValidateUtils;
import com.lecyon.farm.vo.add.AddFmWorkDetailsVo;
import com.lecyon.farm.vo.copy.DuplicateVo;
import com.lecyon.farm.vo.export.ExportFmWorkDetailsVo;
import com.lecyon.farm.vo.modify.ModifyFmWorkDetailsVo;
import com.lecyon.farm.vo.query.QueryFmWorkDetailsVo;
import com.lecyon.farm.vo.request.IdsVo;
import com.lecyon.farm.vo.request.TotalWorkQuantity;
import com.lecyon.farm.vo.status.StatusVo;
import com.lecyon.farm.vo.view.FmWorkDetailsVo;
import com.lecyon.farm.vo.view.StatisticByAreaAndWorkTypePerYear;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import javax.annotation.PostConstruct;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 农机当季作业详情表 服务实现类
 *
 * @author YaoZheng
 * @since 2020-04-02
 */
@Service
@Validated
public class FmWorkDetailsServiceImpl extends ServiceImpl<FmWorkDetailsMapper, FmWorkDetails> implements IFmWorkDetailsService {

    private static final Logger LOG = LoggerFactory.getLogger(FmWorkServiceImpl.class);

    private FmWorkDetailsMapper mapper;

    private IJsSysOfficeService jsSysOfficeService;

    private IFmCarService fmCarService;

    private RedisUtils redisUtils;

    private IExcelService excelService;


    /**
     * 新增农机当季作业详情
     *
     * @param addVo 新增农机当季作业详情对象
     * @return 新增记录的id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse<Long> add(AddFmWorkDetailsVo addVo) {
        RestResponse<Long> result = new RestResponse<>();
        //有效性校验
        //必填项校验
        //重复性校验
        FmWorkDetails entity = new FmWorkDetails();
        BeanUtils.copyProperties(addVo, entity);
        //逻辑校验
        result = logicValidate(entity, result);
        if (!result.isSuccess()) {
            return result;
        }
        boolean flag = entity.insert();
        if (!flag) {
            LOG.warn("FmWorkDetails add method invoke failed. vo :{}", addVo.toString());
            return ResultUtil.error(null, CommonConstant.EX_DB_INSERT_ERROR, "新增失败！");
        }
        LOG.info("FmWorkDetails add method invoke success. vo : {}", addVo.toString());
        return ResultUtil.success(null, entity.getId());
    }

    @Override
    public RestResponse<Long> cumulative(AddFmWorkDetailsVo addVo) {
        return null;
    }

    /**
     * 编辑农机当季作业详情
     *
     * @param modifyVo 编辑对象
     * @return RestResponse
     */
    @Override
    public RestResponse<Long> modify(ModifyFmWorkDetailsVo modifyVo) {
        //有效性校验
        //必填项校验
        RestResponse<Long> result = new RestResponse<>();
        FmWorkDetails entity = new FmWorkDetails();
        BeanUtils.copyProperties(modifyVo, entity);
        //逻辑校验
        result = logicValidate(entity, result);
        if (!result.isSuccess()) {
            return result;
        }
        boolean flag = entity.updateById();
        if (!flag) {
            LOG.warn("FmWorkDetails modify method invoke failed. vo :{}", modifyVo.toString());
            return ResultUtil.error(null, CommonConstant.EX_DB_UPDATE_ERROR, "编辑失败！");
        }
        LOG.info("FmWorkDetails modify method invoke success. vo : {}", modifyVo.toString());
        return ResultUtil.success(null, entity.getId());
    }

    /**
     * 复制农机当季作业详情
     *
     * @param duplicateVo 复制对象Vo
     * @return
     */
    @Override
    public RestResponse<Long> duplicate(DuplicateVo duplicateVo) {
        return null;
    }

    @Override
    public BaseResponse changeStatus(StatusVo statusVo) {
        return null;
    }

    /**
     * 查看记录
     *
     * @param vo 查询条件(id)
     * @return 查询结果
     */
    @Override
    public RestResponse<FmWorkDetailsVo> get(QueryFmWorkDetailsVo vo) {
        RestResponse<FmWorkDetailsVo> result = new RestResponse<>();
        if (ValidateUtils.isNullOrEmpty(vo) || StringHelper.isEmpty(vo.getId())) {
            return ResultUtil.error(result, CommonConstant.EX_FORM_VALIDATE_REQUIRED, "缺少必要的查询条件！");
        }
        FmWorkDetailsVo resultVo = mapper.selectByPrimaryKey(vo);
        if (ValidateUtils.isNullOrEmpty(resultVo)) {
            return ResultUtil.error(result, CommonConstant.EX_DB_SELECT_MISS, "未找到符合条件的记录！");
        }
        return ResultUtil.success(result, resultVo);
    }

    /**
     * 查询列表
     *
     * @param vo 查询条件(包含分页）
     * @return 查询结果
     */
    @Override
    public RestResponse<Page<FmWorkDetailsVo>> getPageList(BaseRequestPageVo<QueryFmWorkDetailsVo> vo) {
        RestResponse<Page<FmWorkDetailsVo>> result = new RestResponse<>();
        QueryFmWorkDetailsVo queryCondition = vo.getEntity(QueryFmWorkDetailsVo.class);
        Page<FmWorkDetailsVo> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        if (CollectionUtils.isNotEmpty(vo.getOrders())) {
            List<OrderItem> orderItemList = CommonService.batchAddPrefix4OrderColumn(vo.getOrders());
            page.setOrders(orderItemList);
        } else {
            page.setOrders(CommonConstant.orderItemList);
        }
        page = mapper.selectByPage(page, queryCondition);
        return ResultUtil.success(result, page);
    }

    /**
     * 查询列表
     *
     * @param vo 查询条件（不含分页信息）
     * @return 查询结果
     */
    @Override
    public RestResponse<List<FmWorkDetailsVo>> getList(BaseRequestVo<QueryFmWorkDetailsVo> vo) {
        RestResponse<List<FmWorkDetailsVo>> result = new RestResponse<>();
        QueryFmWorkDetailsVo queryCondition = vo.getEntity(QueryFmWorkDetailsVo.class);
        List<FmWorkDetailsVo> resultVoList = mapper.selectByCondition(queryCondition);
        return ResultUtil.success(result, resultVoList);
    }

    /**
     * 根据条件查询结果,并导出到Excel
     *
     * @param vo 查询条件
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse<String> exportExcel(BaseRequestVo<QueryFmWorkDetailsVo> vo) {
        RestResponse<String> result = new RestResponse<>();
        List<ExportFmWorkDetailsVo> resultList = Lists.newArrayList();
        RestResponse<List<FmWorkDetailsVo>> queryResult = getList(vo);
        List<FmWorkDetailsVo> voList = null;
        if (queryResult.isSuccess()) {
            voList = queryResult.getData();
        }
        if (CollectionUtils.isNotEmpty(voList)) {
            for (FmWorkDetailsVo temp : voList) {
                ExportFmWorkDetailsVo exportVo = new ExportFmWorkDetailsVo();
                BeanUtils.copyProperties(temp, exportVo);
                resultList.add(exportVo);
            }
        }
        String downLoadUrl;
        try {
            downLoadUrl = excelService.exportExcel(resultList, ExcelFileEnum.FM_WORK);
            if (StringHelper.isEmpty(downLoadUrl)) {
                return ResultUtil.success(result, downLoadUrl);
            }
        } catch (IOException e) {
            throw new FarmException(CommonConstant.EX_EXCEL_ERROR, e.getMessage());
        }
        return ResultUtil.success(result, downLoadUrl);
    }

    /**
     * 通用删除方法，包含批量删除与单条删除
     *
     * @param vo 删除条件
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse delete(@NotNull IdsVo vo) {
        if (ValidateUtils.isNullOrEmpty(vo.getId()) && CollectionUtils.isEmpty(vo.getIdsList())) {
            LOG.warn("FmWorkDetails delete params is null.", this.getClass().getSimpleName());
            return ResultUtil.error(CommonConstant.EX_FORM_VALIDATE_REQUIRED, "缺少必要的参数！");
        }
        List<Long> idsList = vo.getIdsList();
        if (CollectionUtils.isNotEmpty(idsList)) {
            //如果idList不为空，优先进行批量删除
            return deleteByIds(idsList);
        }
        Long id = vo.getId();
        return deleteById(id);
    }

    /**
     * 删除农机当季作业详情
     *
     * @param id 主键ID
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse deleteById(Long id) {
        boolean flag = removeById(id);
        if (!flag) {
            LOG.error("FmWorkDetails delete unsuccessful. id :{}", id);
            return ResultUtil.error(CommonConstant.EX_DB_DELETE_ERROR, "删除记录失败！");
        }
        return ResultUtil.success();
    }

    /**
     * 批量删除农机当季作业详情
     *
     * @param idList 主键ID列表
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse deleteByIds(List<Long> idList) {
        boolean flag = removeByIds(idList);
        if (!flag) {
            LOG.error("FmWorkDetails delete batch unsuccessful. ids :{}", idList);
            return ResultUtil.error(CommonConstant.EX_DB_DELETE_ERROR, "批量删除失败");
        }
        return ResultUtil.success();
    }

    /**
     * 获取地块数量（昨天）
     * 按不同Area进行统计
     *
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    @Scheduled(fixedRate = FarmSysConstant.SCHEDULE_FIX_RATE_PER_DAY)
    public BaseResponse statisticAreaFmWorkDetailsCount() {
//        QueryWrapper<JsSysOffice> jsSysOfficeQueryWrapper = new QueryWrapper<>();
//        jsSysOfficeQueryWrapper.lt("office_type",4);
        List<JsSysOffice> jsSysOfficeList = jsSysOfficeService.list();
        if (CollectionUtils.isEmpty(jsSysOfficeList)) {
            return ResultUtil.success();
        }
        LocalDate yesterday = LocalDate.now(ZoneId.systemDefault()).plusDays(-1);
        LocalDateTime queryBeginTime = LocalDateTime.of(yesterday, LocalTime.MIN);
        LocalDateTime queryEndTime = LocalDateTime.of(yesterday, LocalTime.MAX);
        String code, type;
        QueryWrapper<FmCar> fmCarQueryWrapper;
        QueryWrapper<FmWorkDetails> fmWorkDetailsQueryWrapper = new QueryWrapper<>();
        fmWorkDetailsQueryWrapper.between("work_date", queryBeginTime, queryEndTime);
        int count;
        List<FmCar> fmCarList;
        Set<String> fmCarIdSet = Sets.newTreeSet();
        boolean redisFlag;
        for (JsSysOffice jsSysOffice : jsSysOfficeList) {
            if (StringHelper.isEmpty(jsSysOffice.getOfficeCode()) || StringHelper.isEmpty(jsSysOffice.getOfficeType())) {
                continue;
            }
            fmCarIdSet.clear();
            fmCarQueryWrapper = new QueryWrapper<>();
            fmWorkDetailsQueryWrapper = new QueryWrapper<>();
            fmWorkDetailsQueryWrapper.between("work_date", queryBeginTime, queryEndTime);
            code = jsSysOffice.getOfficeCode();
            type = jsSysOffice.getOfficeType();
            switch (type) {
                case "1":
                    //省级机构
                    fmCarQueryWrapper.eq("province", code);
                    break;
                case "2":
                    //市级机构
                    fmCarQueryWrapper.eq("city", code);
                    break;
                case "3":
                    //区县级机构
                    fmCarQueryWrapper.eq("county", code);
                    break;
                default:
                    //乡镇级机构
                    fmCarQueryWrapper.eq("towns", code);
                    break;
            }
            fmCarList = fmCarService.list(fmCarQueryWrapper);
            if (CollectionUtils.isEmpty(fmCarList)) {
                continue;
            }
            fmCarList.stream().forEach(fmCar -> {
                fmCarIdSet.add(fmCar.getCarId());
            });
            if (CollectionUtils.isEmpty(fmCarIdSet)) {
                continue;
            }
            fmWorkDetailsQueryWrapper.in("car_id", fmCarIdSet);
            count = count(fmWorkDetailsQueryWrapper);
            redisFlag = redisUtils.hSet(FarmSysConstant.REDIS_KEY_FM_WORK_DETAIL_COUNT_YESTERDAY, code, JSON.toJSONString(count));
            if (!redisFlag) {
                throw new FarmException(CommonConstant.EX_DB_REDIS_ERROR, "系统缓存异常");
            }
        }
        return ResultUtil.success();
    }

    /**
     * 根据区域号获取昨日地块数量
     *
     * @param officeCode
     * @return
     */
    @Override
    public RestResponse<Integer> getAreaFmWorkDetailsCount(String officeCode) {
        RestResponse<Integer> result = new RestResponse<>();
        Integer count = 0;
        boolean redisFlag;
        redisFlag = redisUtils.hHasKey(FarmSysConstant.REDIS_KEY_FM_WORK_DETAIL_COUNT_YESTERDAY, officeCode);
        if (redisFlag) {
            String jsonStr = (String) redisUtils.hGet(FarmSysConstant.REDIS_KEY_FM_WORK_DETAIL_COUNT_YESTERDAY, officeCode);
            count = Integer.parseInt(jsonStr);
        }
        return ResultUtil.success(result, count);
    }

    /**
     * 计算活动主机数量（昨天）
     * 按不同Area进行统计
     *
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Scheduled(fixedRate = FarmSysConstant.SCHEDULE_FIX_RATE_PER_DAY)
    public BaseResponse statisticActiveDeviceCount() {
        List<JsSysOffice> jsSysOfficeList = jsSysOfficeService.list();
        if (CollectionUtils.isEmpty(jsSysOfficeList)) {
            return ResultUtil.success();
        }
        LocalDate yesterday = LocalDate.now(ZoneId.systemDefault()).plusDays(-1);
        LocalDateTime queryBeginTime = LocalDateTime.of(yesterday, LocalTime.MIN);
        LocalDateTime queryEndTime = LocalDateTime.of(yesterday, LocalTime.MAX);
        String code, type;
        QueryWrapper<FmCar> fmCarQueryWrapper;
        QueryWrapper<FmWorkDetails> fmWorkDetailsQueryWrapper = new QueryWrapper<>();
        fmWorkDetailsQueryWrapper.between("work_date", queryBeginTime, queryEndTime);
        int count;
        List<FmCar> fmCarList;
        Set<String> fmCarIdSet = Sets.newTreeSet();
        boolean redisFlag;
        Set<String> fmDetailIdSet = Sets.newTreeSet();
        for (JsSysOffice jsSysOffice : jsSysOfficeList) {
            if (StringHelper.isEmpty(jsSysOffice.getOfficeCode()) || StringHelper.isEmpty(jsSysOffice.getOfficeType())) {
                continue;
            }
            fmDetailIdSet.clear();
            fmCarIdSet.clear();
            fmCarQueryWrapper = new QueryWrapper<>();
            fmWorkDetailsQueryWrapper = new QueryWrapper<>();
            fmWorkDetailsQueryWrapper.between("work_date", queryBeginTime, queryEndTime);
            code = jsSysOffice.getOfficeCode();
            type = jsSysOffice.getOfficeType();
            switch (type) {
                case "1":
                    //省级机构
                    fmCarQueryWrapper.eq("province", code);
                    break;
                case "2":
                    //市级机构
                    fmCarQueryWrapper.eq("city", code);
                    break;
                case "3":
                    //区县级机构
                    fmCarQueryWrapper.eq("county", code);
                    break;
                default:
                    //乡镇级机构
                    fmCarQueryWrapper.eq("towns", code);
                    break;
            }
            fmCarList = fmCarService.list(fmCarQueryWrapper);
            if (CollectionUtils.isEmpty(fmCarList)) {
                continue;
            }
            fmCarList.stream().forEach(fmCar -> {
                fmCarIdSet.add(fmCar.getCarId());
            });
            if (CollectionUtils.isEmpty(fmCarIdSet)) {
                continue;
            }
            fmWorkDetailsQueryWrapper.in("car_id", fmCarIdSet);
            List<FmWorkDetails> resultList = list(fmWorkDetailsQueryWrapper);
            if (CollectionUtils.isNotEmpty(resultList)) {
                resultList.stream().forEach(fmWorkDetails -> {
                    fmDetailIdSet.add(fmWorkDetails.getId());
                });
            }
            count = fmDetailIdSet.size();
            redisFlag = redisUtils.hSet(FarmSysConstant.REDIS_KEY_ACTIVE_DEVICE_COUNT_YESTERDAY, code, JSON.toJSONString(count));
            if (!redisFlag) {
                throw new FarmException(CommonConstant.EX_DB_REDIS_ERROR, "系统缓存异常");
            }
        }
        return ResultUtil.success();
    }

    /**
     * 根据区域号获取昨日地块数量
     *
     * @param officeCode
     * @return
     */
    @Override
    public RestResponse<Integer> getActiveDeviceCount(String officeCode) {
        RestResponse<Integer> result = new RestResponse<>();
        Integer count = 0;
        boolean redisFlag;
        redisFlag = redisUtils.hHasKey(FarmSysConstant.REDIS_KEY_ACTIVE_DEVICE_COUNT_YESTERDAY, officeCode);
        if (redisFlag) {
            String jsonStr = (String) redisUtils.hGet(FarmSysConstant.REDIS_KEY_ACTIVE_DEVICE_COUNT_YESTERDAY, officeCode);
            count = Integer.parseInt(jsonStr);
        }
        return ResultUtil.success(result, count);
    }

    /**
     * 分区域按年份统计作业量
     *
     * @return
     */
    @PostConstruct
    @Scheduled(fixedRate = FarmSysConstant.SCHEDULE_FIX_RATE)
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse statisticWorkQuantityByAreaPerYear() {
        LocalDateTime currentDate = LocalDateTime.now(ZoneId.systemDefault());
        int year = currentDate.getYear();
        LocalDateTime queryBeginTime = currentDate.with(TemporalAdjusters.firstDayOfYear());
        LocalDateTime queryEndTime = currentDate.with(TemporalAdjusters.lastDayOfYear());
        if (currentDate.isBefore(queryEndTime)) {
            queryEndTime = currentDate;
        }
        boolean redisFlag;
        int count;
        Map<String, String> sysJobTypeMap = FarmSysConstant.SYS_JOB_TYPE_MAP;
        QueryFmWorkDetailsVo queryFmWorkDetailsVo;
        QueryWrapper<FmWorkDetails> fmWorkDetailsQueryWrapper;
        String officeCode, officeType, officeName;
        List<TotalWorkQuantity> totalWorkQuantityList = Lists.newLinkedList();
        List<JsSysOffice> jsSysOfficeList = jsSysOfficeService.getAll();
        List<StatisticByAreaAndWorkTypePerYear> statisticByAreaAndWorkTypePerYearList;
        if (CollectionUtils.isNotEmpty(jsSysOfficeList)) {
            String itemKey;
            String key = FarmSysConstant.REDIS_KEY_STATISTIC_TOTAL_WORK_QUANTITY;
            for (JsSysOffice jsSysOffice : jsSysOfficeList) {
                itemKey = jsSysOffice.getOfficeCode();
                totalWorkQuantityList.clear();
                queryFmWorkDetailsVo = new QueryFmWorkDetailsVo();
                fmWorkDetailsQueryWrapper = new QueryWrapper<>();
                queryFmWorkDetailsVo.setQueryBeginTime(queryBeginTime);
                queryFmWorkDetailsVo.setQueryEndTime(queryEndTime);
                officeCode = jsSysOffice.getOfficeCode();
                officeType = jsSysOffice.getOfficeType();
                officeName = jsSysOffice.getOfficeName();
                if ("1".equals(officeType)) {
                    continue;
                }
                switch (officeType) {
                    case "2":
                        //市级机构区域
                        queryFmWorkDetailsVo.setLocationCity(officeName);
                        fmWorkDetailsQueryWrapper.eq("location_city", officeName);
                        break;
                    case "3":
                        //区县级机构区域
                        queryFmWorkDetailsVo.setLocationDistrict(officeName);
                        fmWorkDetailsQueryWrapper.eq("location_district", officeName);
                        break;
                    case "4":
                        //乡镇级机构区域
                        queryFmWorkDetailsVo.setLocationTownship(officeName);
                        fmWorkDetailsQueryWrapper.eq("location_township", officeName);
                        break;
                    default:
                        //省级机构区域
                        break;
                }
                String workType, workTypeName;
                count = count(fmWorkDetailsQueryWrapper);
                if (0 == count) {
                    continue;
                }
                statisticByAreaAndWorkTypePerYearList = mapper.statisticByAreaAndWorkTypePerYear(queryFmWorkDetailsVo);
                if (CollectionUtils.isNotEmpty(statisticByAreaAndWorkTypePerYearList)) {
                    for (StatisticByAreaAndWorkTypePerYear statisticVo : statisticByAreaAndWorkTypePerYearList) {
                        TotalWorkQuantity totalWorkQuantity = new TotalWorkQuantity();
                        BeanUtils.copyProperties(statisticVo, totalWorkQuantity);
                        workType = statisticVo.getTypeCode();
                        workTypeName = sysJobTypeMap.get(workType);
                        totalWorkQuantity.setTypeName(workTypeName);
                        totalWorkQuantity.setAreaCode(officeCode);
                        totalWorkQuantity.setAreaName(officeName);
                        totalWorkQuantity.setStatisticYear(year);
                        totalWorkQuantity.setOwner(jsSysOffice.getParentCode());
                        totalWorkQuantityList.add(totalWorkQuantity);
                    }
                }
                if (CollectionUtils.isNotEmpty(totalWorkQuantityList)) {
                    redisFlag = redisUtils.hSet(key, itemKey, JSON.toJSONString(totalWorkQuantityList));
                    if (!redisFlag) {
                        throw new FarmException(CommonConstant.EX_DB_REDIS_ERROR, "系统缓存数据库异常");
                    }
                }
            }
        }
        return ResultUtil.success();
    }

    /**
     * 逻辑校验规则
     *
     * @param entity       被校验的实体类
     * @param restResponse 消息传递对象
     * @return 结果
     */
    private RestResponse logicValidate(FmWorkDetails entity, RestResponse restResponse) {
        return ResultUtil.success(restResponse, null);
    }

    /**
     * 查询记录是否重复
     * 标准：作业编号
     *
     * @param wokSerial 唯一性条件
     * @return
     */
    private boolean isExist(String wokSerial) {
        if (StringHelper.isEmpty(wokSerial)) {
            return false;
        }
        int count = mapper.selectCount(new QueryWrapper<FmWorkDetails>().eq("work_serial", wokSerial));
        return count > 0 ? true : false;
    }

    /**
     * ----------------------------- 分割线 以下是setter方法，用于替换field上的@Autowired -----------------------------
     **/

    @Autowired
    public void setMapper(FmWorkDetailsMapper mapper) {
        this.mapper = mapper;
    }

    @Autowired
    @Lazy
    public void setExcelService(IExcelService excelService) {
        this.excelService = excelService;
    }

    @Autowired
    @Lazy
    public void setJsSysOfficeService(IJsSysOfficeService jsSysOfficeService) {
        this.jsSysOfficeService = jsSysOfficeService;
    }

    @Autowired
    @Lazy
    public void setFmCarService(IFmCarService fmCarService) {
        this.fmCarService = fmCarService;
    }

    @Autowired
    @Lazy
    public void setRedisUtils(RedisUtils redisUtils) {
        this.redisUtils = redisUtils;
    }

}
